<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<%@ page import="java.util.*" %>  
<%@ page import="category.*"  %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@ include file="/Dmyna/admin/head.jsp" %>
<%
	CategoryManager category = CategoryManager.getInstance();
	int count = category.count();
	List<Category> list = category.selectList();
%>
<c:set var="count" value="<%=count%>" />
<c:set var="list" value="<%=list%>" />

<script type="text/javascript">
function validate(form){
	if(form.cate_name.value == ""){
		alert("분류명 입력하세요.");
		return false;
	}else if(form.cate_sort.value == ""){
		alert("분류순번 입력하세요.");
		return false;
	}else if(form.cate_code.value == ""){
		alert("분류코드 입력하세요.");
		return false;
	}
}

function categoryUpdate(form){
	document.catemove.action = "/categoryUpdate.do";
	document.catemove.cateCode.value = form.cate_big_code.value;
	document.catemove.cateName.value = form.cate_big_name.value;
	document.catemove.cateSort.value = form.cate_big_sort.value;
	document.catemove.submit();
	return false;
}
function categoryDelete(cateCode){
	document.catemove.action = "/categoryDelete.do";
	document.catemove.cateCode.value = cateCode;
	document.catemove.submit();

}
</script>

<!-- 상단제목 -->
<table width="900" align=center cellpadding=0 cellspacing=0>
	<tr>
		<td>
			<div
				style="border:1px solid #ddd; height:34px; background:url(${WEB_ROOT }/img/bbs/title_bg.gif) repeat-x;">
				<div style="font-weight: bold; font-size: 14px; margin: 7px 0 0 10px;" align="center">
					::&nbsp;&nbsp;상품 분류 관리&nbsp;&nbsp;::</div>
			</div>
		</td>
	</tr>
</table>
<p>
<!--  -->
<form action="/categoryInsert.do" method="post" name="insert_Cate" onSubmit="return validate(this)">
<table width="900" border="0" align="center">
<tr bgcolor="#BDBDBD">
	<th width="25%">분류 코드(입력)</th>
	<th width="25%">분류 명(입력)</th>
	<th width="25%">순 번(입력)</th>
	<th width="25%"></th>
</tr>
<tr align="center" bgcolor="#f0f0f0">
	<td><input type="text" name="cate_code" value="" size="20" style="text-align:center" maxlength="2"/></td>
	<td><input type="text" name="cate_name" value="" size="20" style="text-align:center" maxlength="10"/></td>
	<td><input type="text" name="cate_sort" value="" size="20" style="text-align:center" maxlength="2"/></td>
	<td><input  type="submit" value='   입   력   '/></td>
</tr>
</table>
</form>

<!--  -->
<table width="900" border="0" align="center">
<tr align="center">
	<td colspan="5" bgcolor="#FFCBCB">
		<font color="black" >리스트</font>
	</td>
</tr>
</table>

<table width="900" border="0" align="center">
<tr align="center" bgcolor="#BDBDBD">
	<th width="25%">분류 코드</th>
	<th width="25%">분류 명</th>
	<th width="25%">순 번</th>
	<th width="25%" colspan="2"></th>
</tr>
</table>

<c:if test="${empty list }">
<table width="900" border="0" align="center">
<tr>
	<td bgcolor="#f0f0f0" colspan="5" height="200" align="center">자료가 없습니다</td>
</tr>
</table>
</c:if>


<c:if test="${!empty list }">
<c:set var="formCnt" value="0" />
<table width="900" border="0" align="center">
<c:forEach var="writing" items="${list}">
<c:set var="formCnt" value="${ (formCnt+1) }" />
<tr align="center" bgcolor="#f0f0f0" >
	<td>
		<form name="fwrite${formCnt }" method="post" onsubmit="return categoryUpdate(this)">
		<table width="900" border="0" align="center">
		<tr align="center">
			<td width="25%" align="center"><input name="cate_big_code" type="text" value="${writing.cate_big_code}" size="20" style="text-align:center;font-size:9pt;color:#ff0000;background-color:#D5D5D5;" readonly="readonly"/></td>
			<td width="25%" align="center"><input name="cate_big_name" type="text" value="${writing.cate_big_name}" size="20" style="text-align:center"/></td>
			<td width="25%" align="center"><input name="cate_big_sort" type="text" value="${writing.cate_big_sort}" size="20" style="text-align:center"/></td>
			<td width="25%" align="center"><input type="submit" value="   수 정   ">
			<input type="button" value="   삭 제   " onclick="categoryDelete('${writing.cate_big_code}')"/></td>
		</tr>
		</table>
		</form>
	</td>
</tr>
</c:forEach>

<tr>
	<td colspan="5" bgcolor="#f0f0f0" align="right">메인 메뉴가 ${count}개의 검색되었습니다.&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </td>
</tr>
</table>
</c:if>
<!-- 

 -->
<form name="catemove" method="post">
	<input type="hidden" name="cateCode" value="" /> 
	<input type="hidden" name="cateName" value="" />
	<input type="hidden" name="cateSort" value="" />
</form>

<!-- ---------------------------- -->
<%@ include file="/Dmyna/admin/tail.jsp" %>